package com.spagettikod.t437.simpledb;

import java.util.LinkedList;

public class SimpleDBAttribute
{
	private LinkedList<String> values = new LinkedList<String>();

	private String name;

	public SimpleDBAttribute(String name)
	{
		this.name = name;
	}

	public SimpleDBAttribute(String name, String value)
	{
		this.name = name;
		addValue(value);
	}

	public String getName()
	{
		return name;
	}

	public void addValue(String value)
	{
		values.add(value);
	}

	public String getValue(int index)
	{
		return values.get(index);
	}

	public int countValues()
	{
		return values.size();
	}

	public boolean hasMultipleValues()
	{
		return values.size() > 1;
	}

	@Override
	public String toString()
	{
		if (values.size() == 0)
		{
			return null;
		}
		else if (values.size() == 1)
		{
			return values.getFirst();
		}
		else
		{
			StringBuilder b = new StringBuilder();
			for (String s : values)
			{
				if (b.length() > 0)
				{
					b.append(", ");
				}
				b.append(s);
			}
			return b.toString();
		}
	}

}
